import { Inject,Controller,Post,Files, Fields, createMiddleware } from '@midwayjs/core';
import { UploadMiddleware,UploadFileInfo } from '@midwayjs/busboy';
import { Context } from '@midwayjs/koa';
import { UploadSerivce } from '../service/upload.serivce';
@Controller('/fileUpload')
export class fileUpload{

    @Inject()
    ctx: Context;
    @Inject()
    uploadService: UploadSerivce;

    /** 
    * @name 上传文件
    * @description Post/fileUpload/upload
    * @returns object
    */
    @Post('/upload',{ middleware: [ createMiddleware(UploadMiddleware,{mode:'file'}) ]})
        async upload(@Files() files: Array<UploadFileInfo>, @Fields() fields: Record<string, string>) {
            return await this.uploadService.upload(files, fields);
        };
    }
